package us.mooresr.geartrack.server.handler;

import java.util.ArrayList;

import us.mooresr.geartrack.server.DAO;
import us.mooresr.geartrack.shared.action.GetAllItemTypesAction;
import us.mooresr.geartrack.shared.action.GetAllItemTypesResult;
import us.mooresr.geartrack.shared.model.ItemType;

import com.googlecode.objectify.Query;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class GetAllItemTypesActionHandler implements ActionHandler<GetAllItemTypesAction, GetAllItemTypesResult>{

	@Override
	public GetAllItemTypesResult execute(GetAllItemTypesAction arg0,
			ExecutionContext arg1) throws ActionException {
		DAO dao = new DAO();
		

		
		ArrayList<ItemType> itemTypeList = new ArrayList<ItemType>();
		
		Query<ItemType> q = dao.ofy().query(ItemType.class);
		
		for (ItemType r : q) {
			itemTypeList.add(r);
		}
		
		return new GetAllItemTypesResult(itemTypeList);
	}

	@Override
	public Class<GetAllItemTypesAction> getActionType() {
		return GetAllItemTypesAction.class;
	}

	@Override
	public void undo(GetAllItemTypesAction arg0, GetAllItemTypesResult arg1,
			ExecutionContext arg2) throws ActionException {
		// TODO Auto-generated method stub
		
	}

}
